package com.utils.basejava.concurrent.Thread;

import java.io.IOException;
import java.io.PipedReader;
import java.io.PipedWriter;

public class Piped {
	
	public static void main(String[] args) throws IOException, InterruptedException {
		PipedWriter out = new PipedWriter();
		PipedReader in = new PipedReader();
		out.connect(in);
		Thread printThread = new Thread(new Print(in),"printThread");
		printThread.start();
		int recive = 0;
		try {
			while((recive=System.in.read())!=-1) {
				out.write(recive);
			}
		}finally {
			out.close();
		}
	}
	
	static class Print implements Runnable{
		
		private PipedReader in;
		
		public Print(PipedReader in) {
			this.in=in;
		}

		public void run() {
			int recive = 0;
			try {
				while((recive=in.read())!=-1) {
					System.out.println((char)recive);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
	}
	
	
}
